<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表单提交示例</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
        }

        form {
            border: 1px solid #e0e0e0;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
            width: 300px;
        }

        label {
            display: block;
            margin-bottom: 5px;
        }

        input[type="text"] {
            width: 100%;
            padding: 8px;
            margin-bottom: 15px;
            border: 1px solid #ccc;
            border-radius: 3px;
        }

        /* 让性别选择横向排列 */
        .gender-radio {
            display: flex;
            align-items: center;
        }

        .gender-radio label {
            margin-right: 15px;
        }

        button {
            background-color: #007BFF;
            color: white;
            padding: 8px 15px;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }

        ul {
            list-style-type: none;
            padding: 0;
            margin-left: 20px;
            width: 200px;
        }

        li {
            border: 1px solid #e0e0e0;
            padding: 10px;
            margin-bottom: 10px;
            border-radius: 3px;
        }
    </style>
</head>

<body>
<div id="app">
    <form>
        <label for="name">姓名:</label>
        <input type="text" id="name" v-model="formData.name">
        <label for="gender">性别:</label>
        <div class="gender-radio">
            <input type="radio" id="male" value="男" v-model="formData.gender">
            <label for="male">男</label>
            <input type="radio" id="female" value="女" v-model="formData.gender">
            <label for="female">女</label>
        </div>
        <label for="hobby">爱好:</label>
        <input type="text" id="hobby" v-model="formData.hobby">
        <button type="button" @click="addItem">添加</button>
    </form>
    <ul>
        <li v-for="(item, index) in itemList" :key="index">{{ item.name }} ({{ item.gender }}) 喜欢{{ item.hobby }}</li>
    </ul>
</div>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script>
    const { createApp } = Vue;
    const app = createApp({
        data() {
            return {
                formData: {
                    name: '',
                    gender: '',
                    hobby: ''
                },
                itemList: [
                    { name: '赵三', gender: '女', hobby: '打篮球' },
                    { name: '王二', gender: '男', hobby: '下象棋' },
                    { name: '黄四', gender: '男', hobby: '吃饭' }
                ]
            };
        },
        methods: {
            addItem() {
                if (this.formData.name && this.formData.gender && this.formData.hobby) {
                    this.itemList.push({
                        name: this.formData.name,
                        gender: this.formData.gender,
                        hobby: this.formData.hobby
                    });
                    // 清空表单数据
                    this.formData.name = '';
                    this.formData.gender = '';
                    this.formData.hobby = '';
                }
            }
        }
    });
    app.mount('#app');
</script>
</body>

</html>